<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import LoadingPlugin from '@/plugins/loading';
import { useUserStore } from '@/store/modules/user';
import { ACCESS_TOKEN } from '@/store/mutation-types';

const route = useRoute();
const router = useRouter();
const userStore = useUserStore();
const isErr = ref(false);

onMounted(() => {
  LoadingPlugin.open();
  let path = route.query.path;
  let token = route.query.token;
  if (token) {
    let updateToken = `Bearer ${token}`;
    localStorage.setItem(ACCESS_TOKEN, updateToken);
    userStore.setToken(updateToken);
    LoadingPlugin.close();
    router.replace({
      path: path ? path : '/',
    });
  } else {
    LoadingPlugin.close();
    isErr.value = true;
  }
});
</script>
<template>
  <n-result
    v-if="isErr"
    status="404"
    title="参数错误"
    style="margin-top: 12%"
    description="请检查参数是否有问题"
  >
  </n-result>
</template>
<style></style>
